package com.library.service;

import com.library.dao.UserRepository;
import com.library.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * user service，执行对user的数据库查询等操作
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    /**
     *
     * @return 返回id和userName的hashMap
     */
    public Map<Long,String> getId_Name(){
        Map<Long,String> map = new HashMap<>();
        List<User> users = userRepository.findAll();
        for (User user : users) {
            map.put(user.getId(),user.getUserName());
        }
        return map;
    }



}
